<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <meta name="author" content="林镭特" />
    <title></title>
    <style></style>
  </head>
  <body>
    <button>增加</button>
    <ul>
      <li>第1个</li>
      <li>第2个</li>
      <li>第3个</li>
    </ul>
    <script>
      var button = document.querySelector("button");
      var lis = document.querySelectorAll("li");
      var ul = document.querySelector("ul");
      var index = 3;

      button.onclick = function() {
        var addli = document.createElement("li");
        ul.appendChild(addli);
        index++;
        addli.innerHTML = "第" + index + "个";
        lis = document.querySelectorAll("li");
        // ev.stopPropagation()
        console.log(lis);

        for (var i = 0; i < lis.length; i++) {
          color();
        }
      };
      color();
      function color() {
        for (var i = 0; i < lis.length; i++) {
          lis[i].onmouseenter = function(ev) {
            this.style.color = "red";
            ev.stopPropagation();
          };
          lis[i].onmouseleave = function() {
            this.style.color = "black";
            //   ev.stopPropagation()
          };
        }
      }
    </script>
  </body>
</html>
